package org.jeecg.modules.professional.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.professional.entity.Professional;
import org.jeecg.modules.professional.entity.vo.ProfessionalVO;
import org.jeecg.modules.professional.mapper.ProfessionalMapper;
import org.jeecg.modules.professional.service.ProfessionalService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liujiamiao
 * @since 2020-11-05
 */
@Service
public class ProfessionalServiceImpl extends ServiceImpl<ProfessionalMapper, Professional> implements ProfessionalService {

    private int count = 0;

    /**
     * 分页查询
     * @param page
     * @param size
     * @param basicId
     * @return
     */
    @Override
    public IPage<Professional> pageSelect(Integer page, Integer size, Integer basicId) {
        Page<Professional> pageWrapper = new Page<>(page, size);
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("basic_id",basicId);
        IPage<Professional> ipage = this.page(pageWrapper, wrapper);
        count = (page-1)*size;
        List<Professional> collect = ipage.getRecords().stream().map(entity -> {
            ProfessionalVO vo = new ProfessionalVO();
            BeanUtils.copyProperties(entity, vo);
            vo.setSerialNumber(++count);
            return vo;
        }).collect(Collectors.toList());

        ipage.setRecords(collect);
        return ipage;
    }




}
